home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / Sounds.as < prev    next >
Text File  |  2013-04-24  |  8KB  |  282 lines

  1. class Sounds
  2. {
  3.    static var nFADE_SPEED = 5;
  4.    function Sounds(_mcTimeline)
  5.    {
  6.       this.mcTimeLine = _mcTimeline;
  7.       this.init();
  8.       this.mcRef = _mcTimeline.mcSounds;
  9.       this.mcRef.onEnterFrame = Delegate.create(this,this.enterFrame);
  10.    }
  11.    function isSoundsMuted()
  12.    {
  13.       return this.bMuteSound;
  14.    }
  15.    function isMusicMuted()
  16.    {
  17.       return this.bMuteMusic;
  18.    }
  19.    function playSound(_sName, _nVolume, _nLoop)
  20.    {
  21.       if(!this.exist(_sName))
  22.       {
  23.          this.oSounds[_sName] = new Object();
  24.          this.oSounds[_sName].sName = _sName;
  25.          this.oSounds[_sName].nVolume = 0;
  26.          this.oSounds[_sName].nPausePosition = 0;
  27.          this.oSounds[_sName].mcRef = this.mcTimeLine.createEmptyMovieClip(_sName,this.nDepth);
  28.          this.oSounds[_sName].sSound = new Sound(_sName);
  29.          this.oSounds[_sName].sSound.attachSound(_sName);
  30.          if(_sName == Controller.PACKAGING_INTRO_MUSIC_NAME)
  31.          {
  32.             this.oSounds[_sName].sSound.onSoundComplete = Delegate.create(Controller.getRef(),Controller.getRef().introComplete);
  33.          }
  34.          this.nDepth = this.nDepth + 1;
  35.       }
  36.       if(this.exist(_sName))
  37.       {
  38.          this.setVolumeSound(_sName,_nVolume);
  39.          this.oSounds[_sName].sSound.start(0,_nLoop);
  40.          if(this.isMusic(_sName))
  41.          {
  42.             if(this.bMuteMusic)
  43.             {
  44.                this.oSounds[_sName].sSound.setVolume(0);
  45.             }
  46.          }
  47.          else if(this.bMuteSound)
  48.          {
  49.             this.oSounds[_sName].sSound.setVolume(0);
  50.          }
  51.       }
  52.    }
  53.    function playRandomSound(_nMaxSounds, _sSoundName, _nVolume)
  54.    {
  55.       var _loc5_ = Math.round(Math.random() * (_nMaxSounds - 1));
  56.       _loc5_ = _loc5_ + 1;
  57.       this.playSound(_sSoundName + "(" + _loc5_ + ")",_nVolume,1);
  58.    }
  59.    function stopSound(_sName)
  60.    {
  61.       if(this.exist(_sName))
  62.       {
  63.          this.setVolumeSound(_sName,0);
  64.          this.oSounds[_sName].sSound.stop();
  65.       }
  66.    }
  67.    function pauseSound(_sName)
  68.    {
  69.       if(this.exist(_sName))
  70.       {
  71.          if(!this.isMusic(_sName))
  72.          {
  73.             if(this.oSounds[_sName].nPausePosition == -1)
  74.             {
  75.                this.oSounds[_sName].nPausePosition = 0;
  76.             }
  77.             else
  78.             {
  79.                this.oSounds[_sName].nPausePosition = this.oSounds[_sName].sSound.position;
  80.             }
  81.             this.oSounds[_sName].sSound.stop();
  82.          }
  83.       }
  84.    }
  85.    function resumeSound(_sName)
  86.    {
  87.       if(this.exist(_sName))
  88.       {
  89.          if(!this.isMusic(_sName))
  90.          {
  91.             if(this.oSounds[_sName].nPausePosition != 0 && this.oSounds[_sName].nPausePosition != undefined)
  92.             {
  93.                this.oSounds[_sName].sSound.start(this.oSounds[_sName].nPausePosition / 1000,0);
  94.             }
  95.          }
  96.       }
  97.    }
  98.    function pauseAllSounds()
  99.    {
  100.       for(var i in this.oSounds)
  101.       {
  102.          this.pauseSound(this.oSounds[i].sName);
  103.       }
  104.    }
  105.    function resumeAllSounds()
  106.    {
  107.       for(var i in this.oSounds)
  108.       {
  109.          this.resumeSound(this.oSounds[i].sName);
  110.       }
  111.    }
  112.    function startFadeIn(_sName, _nVolume, _nLoop)
  113.    {
  114.       if(!this.bMuteSound && !this.isMusic(_sName) || !this.bMuteMusic && this.isMusic(_sName))
  115.       {
  116.          this.playSound(_sName,0,_nLoop);
  117.          var _loc5_ = [_sName,_nVolume,"In",0];
  118.          this.aTabSonFade.push(_loc5_);
  119.       }
  120.       else
  121.       {
  122.          this.playSound(_sName,_nVolume,_nLoop);
  123.       }
  124.    }
  125.    function startFadeOut(_sName)
  126.    {
  127.       if(this.exist(_sName))
  128.       {
  129.          this.aTabSonFade = [];
  130.          if(this.oSounds[_sName].sSound.getVolume() != 0)
  131.          {
  132.             var _loc3_ = [_sName,0,"Out",this.oSounds[_sName].sSound.getVolume()];
  133.             this.aTabSonFade.push(_loc3_);
  134.          }
  135.          else
  136.          {
  137.             this.stopSound(_sName);
  138.          }
  139.       }
  140.    }
  141.    function setVolumeSound(_sName, _nVolume)
  142.    {
  143.       if(this.exist(_sName))
  144.       {
  145.          this.oSounds[_sName].nVolume = _nVolume;
  146.          if(this.bMuteSound && !this.isMusic(_sName) || this.bMuteMusic && this.isMusic(_sName))
  147.          {
  148.             this.oSounds[_sName].sSound.setVolume(0);
  149.          }
  150.          else
  151.          {
  152.             this.oSounds[_sName].sSound.setVolume(_nVolume);
  153.          }
  154.       }
  155.    }
  156.    function DoMuteSounds()
  157.    {
  158.       this.bMuteSound = true;
  159.       for(var i in this.oSounds)
  160.       {
  161.          if(!this.isMusic(this.oSounds[i].sName))
  162.          {
  163.             this.oSounds[this.oSounds[i].sName].sSound.setVolume(0);
  164.          }
  165.       }
  166.    }
  167.    function UndoMuteSounds()
  168.    {
  169.       this.bMuteSound = false;
  170.       for(var i in this.oSounds)
  171.       {
  172.          if(!this.isMusic(this.oSounds[i].sName))
  173.          {
  174.             this.setVolumeSound(this.oSounds[i].sName,this.oSounds[i].nVolume);
  175.          }
  176.       }
  177.    }
  178.    function DoMuteMusic()
  179.    {
  180.       this.bMuteMusic = true;
  181.       for(var i in this.oSounds)
  182.       {
  183.          if(this.isMusic(this.oSounds[i].sName))
  184.          {
  185.             this.oSounds[this.oSounds[i].sName].sSound.setVolume(0);
  186.          }
  187.       }
  188.    }
  189.    function UndoMuteMusic()
  190.    {
  191.       this.bMuteMusic = false;
  192.       for(var i in this.oSounds)
  193.       {
  194.          if(this.isMusic(this.oSounds[i].sName))
  195.          {
  196.             this.setVolumeSound(this.oSounds[i].sName,this.oSounds[i].nVolume);
  197.          }
  198.       }
  199.    }
  200.    function enterFrame()
  201.    {
  202.       for(var i in this.aTabSonFade)
  203.       {
  204.          var _loc2_ = this.aTabSonFade[i][0];
  205.          var _loc3_ = this.aTabSonFade[i][1];
  206.          var _loc4_ = this.aTabSonFade[i][2];
  207.          var _loc5_ = this.aTabSonFade[i][3];
  208.          if(_loc4_ == "In")
  209.          {
  210.             _loc5_ += this.nFadingSpeed;
  211.             if(_loc5_ >= _loc3_)
  212.             {
  213.                _loc5_ = _loc3_;
  214.                this.deleteFading(_loc2_);
  215.                if(this.aTabSonFade.length == 0)
  216.                {
  217.                   delete this.oSounds[_loc2_].mcRef.onEnterFrame;
  218.                }
  219.             }
  220.          }
  221.          else
  222.          {
  223.             _loc5_ -= this.nFadingSpeed;
  224.             if(_loc5_ <= 0)
  225.             {
  226.                this.stopSound(_loc2_);
  227.                _loc5_ = 0;
  228.                this.deleteFading(_loc2_);
  229.                if(this.aTabSonFade.length == 0)
  230.                {
  231.                   delete this.oSounds[_loc2_].mcRef.onEnterFrame;
  232.                }
  233.             }
  234.          }
  235.          if(_loc5_ != 0)
  236.          {
  237.             this.aTabSonFade[i][3] = _loc5_;
  238.          }
  239.          this.setVolumeSound(_loc2_,_loc5_);
  240.       }
  241.    }
  242.    function deleteFading(_sName)
  243.    {
  244.       var _loc3_ = 0;
  245.       while(_loc3_ <= this.aTabSonFade.length)
  246.       {
  247.          if(this.aTabSonFade[_loc3_][0] == _sName)
  248.          {
  249.             this.aTabSonFade.splice(_loc3_,1);
  250.          }
  251.          _loc3_ = _loc3_ + 1;
  252.       }
  253.    }
  254.    function init()
  255.    {
  256.       this.oSounds = {};
  257.       this.aTabSonFade = [];
  258.       this.bMuteMusic = false;
  259.       this.bMuteSound = false;
  260.       this.nDepth = 0;
  261.       this.nFadingSpeed = Sounds.nFADE_SPEED;
  262.    }
  263.    function exist(_sName)
  264.    {
  265.       var _loc3_ = false;
  266.       if(this.oSounds[_sName])
  267.       {
  268.          _loc3_ = true;
  269.       }
  270.       return _loc3_;
  271.    }
  272.    function isMusic(_sName)
  273.    {
  274.       var _loc3_ = false;
  275.       if(_sName == Controller.GAME_MUSIC_NAME || (_sName == Controller.PACKAGING_INTRO_MUSIC_NAME || _sName == Controller.PACKAGING_MUSIC_NAME))
  276.       {
  277.          _loc3_ = true;
  278.       }
  279.       return _loc3_;
  280.    }
  281. }
  282.